package cn.com.xf.web.form;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.hibernate.validator.constraints.NotEmpty;

import cn.com.xf.domain.TblCheckHoliday;

public class HolidayForm extends BaseForm {

	private String id;
	@NotEmpty(message = "所属公司不能为空")
	private String siteid;
	@NotEmpty(message = "节日名称不能为空")
	private String holidayname;
	@NotEmpty(message = "开始日期不能为空")
	private String startdate;
	@NotEmpty(message = "结束日期不能为空")
	private String enddate;
	private String adduser;
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getSiteid() {
		return siteid;
	}
	public void setSiteid(String siteid) {
		this.siteid = siteid;
	}
	public String getHolidayname() {
		return holidayname;
	}
	public void setHolidayname(String holidayname) {
		this.holidayname = holidayname;
	}
	public String getStartdate() {
		return startdate;
	}
	public void setStartdate(String startdate) {
		this.startdate = startdate;
	}
	public String getEnddate() {
		return enddate;
	}
	public void setEnddate(String enddate) {
		this.enddate = enddate;
	}
	
	public String getAdduser() {
		return adduser;
	}
	public void setAdduser(String adduser) {
		this.adduser = adduser;
	}
	public boolean isEndDateBeforeStartDate() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date start = sdf.parse(startdate);
			Date end = sdf.parse(enddate);
			if (end.before(start))
				return true;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return false;
	}	
	
	public TblCheckHoliday copyTo() throws Exception {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		TblCheckHoliday holiday = new TblCheckHoliday();
		holiday.setSiteid(siteid);
		holiday.setName(holidayname);
		holiday.setStartdate(sdf.parse(startdate));
		holiday.setEnddate(sdf.parse(enddate));
		holiday.setAdduser(adduser);
		holiday.setAddtime(new Date());
		return holiday;
	}
	
	public TblCheckHoliday copyTo(TblCheckHoliday holiday) throws Exception {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		holiday.setSiteid(siteid);
		holiday.setName(holidayname);
		holiday.setStartdate(sdf.parse(startdate));
		holiday.setEnddate(sdf.parse(enddate));
		holiday.setUpdateuser(adduser);
		holiday.setUpdatetime(new Date());
		return holiday;
	}
}
